package mlz.a_charstream;

import org.junit.Test;

import java.io.FileWriter;
import java.io.IOException;

/*
    字符输出流
 */
public class FileWriterDemo02 {
    @Test
    public void test01() throws IOException {
        //1.创建字符输出流对象
        FileWriter fw = new FileWriter("writer1.txt",true);
        //2.写入一个字符
        fw.write('a');
        fw.write(97);
        fw.write("\r\n");

        //3.写入字符串
        fw.write("你好,你吃了吗?abc");

        //4.写入截取后的字符串
        fw.write("你好,你吃了吗?abc",0,5);

        //写入字符数组
        char[] cs = {'你','好','a','b','c'};
        fw.write(cs);
        fw.write(cs,0,2);

        //1.刷新
        //fw.flush();

        //关闭流对象
        fw.close();
    }
}
